import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/layouts/BaseLayout.vue'),
    children: [
      {
        path: '',
        name: 'Home',
        component: () => import('@/views/Home.vue'),
        meta: { title: '首页' }
      },
      {
        path: '/text',
        name: 'TextTools',
        component: () => import('@/views/tools/TextTools.vue'),
        meta: { title: '文本工具' }
      },
      {
        path: '/file',
        name: 'FileTools',
        component: () => import('@/views/tools/FileTools.vue'),
        meta: { title: '文件工具' }
      },
      {
        path: '/image',
        name: 'ImageTools',
        component: () => import('@/views/tools/ImageTools.vue'),
        meta: { title: '图片工具' }
      },
      {
        path: '/video',
        name: 'VideoTools',
        component: () => import('@/views/tools/VideoTools.vue'),
        meta: { title: '视频工具' }
      },
      {
        path: '/audio',
        name: 'AudioTools',
        component: () => import('@/views/tools/AudioTools.vue'),
        meta: { title: '音频处理' }
      },
      {
        path: '/data',
        name: 'DataTools',
        component: () => import('@/views/tools/DataTools.vue'),
        meta: { title: '数据分析' }
      },
      {
        path: '/network',
        name: 'NetworkTools',
        component: () => import('@/views/tools/NetworkTools.vue'),
        meta: { title: '网络工具' }
      },
      {
        path: '/dev',
        name: 'DevTools',
        component: () => import('@/views/tools/DevTools.vue'),
        meta: { title: '开发工具' }
      },
      {
        path: '/encryption',
        name: 'EncryptionTools',
        component: () => import('@/views/tools/EncryptionTools.vue'),
        meta: { title: '加密工具' }
      },
      {
        path: '/format',
        name: 'FormatTools',
        component: () => import('@/views/tools/FormatTools.vue'),
        meta: { title: '格式化工具' }
      },
      {
        path: 'format',
        name: 'Format',
        component: () => import('@/views/tools/FormatTools.vue'),
        meta: { title: '格式化' }
      },
      {
        path: ':pathMatch(.*)*',
        name: 'NotFound',
        component: () => import('@/views/NotFound.vue'),
        meta: { title: '404' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  const title = to.meta?.title as string | undefined
  document.title = title ? `${title} - LanLanWeb在线工具` : 'LanLanWeb在线工具'
  next()
})

export default router 